package com.songjia.springcloud.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RestController;

import com.songjia.common.model.base.ResponseInfo;
import com.songjia.common.model.po.Dept;
import com.songjia.common.service.DeptClientService;
import com.songjia.springcloud.service.DeptService;

/**
 * 
 * 
 * @Description: Feign继承特性
 *
 * @author: songjia
 * @date: 2018年8月30日 下午8:00:46
 */
@RestController
public class DeptController implements DeptClientService {

	@Autowired
	private DeptService deptService;

	@Value("${server.port}")
	private String port;

	/**
	 * 获取部门详情
	 * 
	 * @param id
	 * @return
	 * @see com.songjia.common.service.DeptClientService#get(java.lang.Long)
	 */
	@Override
	public ResponseInfo get(Long id) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Dept deptDetail = this.deptService.getDeptDetail(id);
		resultMap.put("port", port);
		resultMap.put("data", deptDetail);
		return ResponseInfo.success(resultMap);
	}

	/**
	 * 获取部门列表
	 * 
	 * @return
	 * @see com.songjia.common.service.DeptClientService#getAll()
	 */
	@Override
	public ResponseInfo getAll() {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<Dept> deptList = this.deptService.getDeptList();
		resultMap.put("port", port);
		resultMap.put("data", deptList);
		return ResponseInfo.success(resultMap);
	}
}
